<template>
	<view class="p-3">
		<view>
			<bg-title class="mb-3">
				<text class="font-2 font-bold">履行中的合同</text>
			</bg-title>
			<view class="bt-block px24py30 mb-3" v-if="current">
				<view class="flex justify-between align-center" >
					<view>
						<view class="font-14 mb-2">{{current.projectName}}</view>
						<bg-desc label="开始时间" :value="current.startTime"></bg-desc>
					</view>
					<view>
						<bg-btn @click="gotoCon(current.userContractId)" style="width:155rpx;height: 48rpx; font-size: 24rpx;">查看合同</bg-btn>						
					</view>
				</view>
			</view>
			<u-empty v-else></u-empty>
		</view>
		<view>
			<bg-title class="mb-3">
				<text class="font-2 font-bold">历史合同</text>
			</bg-title>
			<view  v-if="history.length>0">
				<view class="bt-block px24py30 mb-3"  v-for="item,idx in history" :key="idx">
					<view class="flex justify-between align-center">
						<view>
							<view class="font-14 mb-2">{{item.projectName}}</view>
							<bg-desc label="开始时间" :value="item.startTime"></bg-desc>
						</view>
						<view>
							<bg-btn @click="gotoCon(item.userContractId)" style="width:155rpx;height: 48rpx; font-size: 24rpx;">查看合同</bg-btn>						
						</view>
					</view>
				</view>
			</view>
			
			<u-empty v-else></u-empty>
			
			
		</view>
	</view>
</template>

<script>
	import { currentContract, historyContract, currentDetail } from '../../../api/mine'
	export default {
		data() {
			return {
				params:{
					pageNum:1,
					pageSize:1000
				},
				current:{},
				history:[]
			}
		},
		mounted() {
			this.getData()
		},
		methods: {
			getData(){
				currentContract().then(res=>{
					this.current=res.data
				})
				historyContract(this.params).then(res=>{
					this.history = res.data.rows
				})
			},
			gotoCon(userContractId){
				currentDetail(userContractId).then(res=>{
					if(res.data.signUrl){
						uni.navigateTo({
							url:"/pages/common/webview/index?url="+encodeURIComponent(res.data.signUrl)+"&title=合同详情"
						})
					}else {
						this.$modal.msg("没有合同地址")
					}
				})
			}
		}
	}
</script>

<style>

</style>
